package org.sport.dbImplement;

import org.sport.dbInterface.SpoHisOperation;
import org.sport.model.entityModel.SporthistorytableEntity;
import org.sport.model.entityModel.UsertableEntity;
import org.sport.repository.SporthistorytableRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Allen on 2017/9/21.
 */

@Service
public class SpoHisOpeImp implements SpoHisOperation {

    @Autowired
    SporthistorytableRepository     sporthistorytableRepository;

    @Override
    public boolean addSpoHisOne(SporthistorytableEntity sporthis) {
        if(sporthis != null)
        {
            sporthistorytableRepository.saveAndFlush(sporthis);
            return true;
        }
        else
            return false;
    }

    @Override
    public boolean updateSpoHisOne(SporthistorytableEntity sporthis) {
        return false;
    }

    @Override
    public boolean delSpoHisByActId(SporthistorytableEntity sporthis) {
        return false;
    }

    @Override
    public SporthistorytableEntity findOneByUserIdAndStartTime(SporthistorytableEntity sporthis) {
        return sporthistorytableRepository.findSpoByUserIdAndStartTime(sporthis.getUsertableByUserId(),sporthis.getStartTiem());
    }

    @Override
    public SporthistorytableEntity findSpoByStartTime(SporthistorytableEntity sporthis) {
        return sporthistorytableRepository.findSpoByStartTime(sporthis.getStartTiem());
    }

/*    @Override
    public SporthistorytableEntity findOneID(SporthistorytableEntity sporthis) {
        return sporthistorytableRepository.findOne(sporthis);
    }*/

    @Override
    public List<SporthistorytableEntity> findSpoHisByUserId(UsertableEntity usertableEntity) {

        return sporthistorytableRepository.findSpoByUserId(usertableEntity);
    }

    @Override
    public List<SporthistorytableEntity> findSpoHis() {
        return sporthistorytableRepository.findAll();
    }
}
